package cym;

public class ShellSort {

    public static void sort(int[] r, int[] d) {
        int n = r.length;
        int j;
        for (int k = 0; k < d.length; k++) {
            int dk = d[k];
            for (int i = dk; i <= n - 1; i++) {
                int temp = r[i];
                for (j = i - dk; j >= 0 && temp < r[j]; j -= dk) {
                    r[j + dk] = r[j];
                }
                r[j + dk] = temp;
            }
        }
    }

    public static void display(int[] r) {
        for (int item : r) {
            System.out.print(item + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] d = new int[]{5, 3, 1};
        int[] r = new int[]{3, 5, 5, 4, 120, 43, 1, 76, 78, 12, 346};
        ShellSort.sort(r, d);
        ShellSort.display(r);
    }

}